const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
// promise封装数据请求
let token = wx.getStorageSync("token"); // 获取储存中的token
function promise_ajax(_url, _type, _data) {
  return new Promise((resolve, reject) => {
    // 弹窗
    wx.showLoading({
      title: '数据加载中',
      mask: true
    })
    wx.request({
      url: _url,
      method: _type,
      data: _data,
      // header:{ // 请求头
      //   "X-Nideshop-Token":token
      // },
      success(res) {
        wx.hideLoading();
        resolve(res);
      },
      fail(err) {
        wx.hideLoading();
        reject(err);
      }
    })
  })
}

// 传参
function biography(_url,_id){
  wx.navigateTo({
    url: _url+'?id='+_id,
  });
}
module.exports = {
  formatTime: formatTime,
  promise_ajax,
  biography
}
